package com.liuyi.netty.im.lychat.modular.service;

import com.liuyi.netty.im.lychat.modular.caches.MessageRecordsCache;
import com.liuyi.netty.im.lychat.modular.entity.MessageRecords;
import com.liuyi.netty.im.lychat.modular.enums.MessageType;
import com.liuyi.netty.im.lychat.modular.enums.SessionType;
import com.liuyi.netty.im.lychat.modular.mapper.MessageRecordsMapper;
import com.liuyi.rapid.develop.mybatis.plus.base.IBaseService;

/**
 * <p>
 * 消息记录表 服务类
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-12-29
 */
public interface IMessageRecordsService extends IBaseService<MessageRecords> {

    @Override
    default Class<MessageRecords> getEntityClass() {
        return MessageRecords.class;
    }

    @Override
    @SuppressWarnings("unchecked")
    default MessageRecordsMapper getMapper() {
        return (MessageRecordsMapper) getBaseMapper();
    }

    MessageRecordsCache cache();

    /**
     * 创建消息
     *
     * @param fromId      发送人
     * @param toId        接收人
     * @param sessionType 会话类型
     * @param contentType 内容类型
     * @param content     内容
     * @return 消息id
     */
    MessageRecords createMessage(String fromId, String toId, SessionType sessionType, MessageType contentType, Object content);

    default void updateSendIs(Long id){
        this.update(new MessageRecords().setSendIs(true),q().eq("id",id));
        cache().removeById(id);
    }
}
